home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 January / january_2001.iso / intercd / root / ^4Developers / VB / visbasdb / VBDB / VBDB Code / VB5 Code / Class 6 / Example6-5.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-09-18  |  7.0 KB  |  242 lines

  1. VERSION 5.00
  2. Begin VB.Form frmAuthors 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Authors"
  5.    ClientHeight    =   2625
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   4680
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   2625
  13.    ScaleWidth      =   4680
  14.    StartUpPosition =   3  'Windows Default
  15.    Begin VB.Data datAuthors 
  16.       Caption         =   "Data1"
  17.       Connect         =   "Access"
  18.       DatabaseName    =   "C:\VBDB\Working\Biblio.mdb"
  19.       DefaultCursorType=   0  'DefaultCursor
  20.       DefaultType     =   2  'UseODBC
  21.       Exclusive       =   0   'False
  22.       Height          =   300
  23.       Left            =   2520
  24.       Options         =   0
  25.       ReadOnly        =   0   'False
  26.       RecordsetType   =   1  'Dynaset
  27.       RecordSource    =   "SELECT * FROM Authors ORDER BY Author"
  28.       Top             =   120
  29.       Visible         =   0   'False
  30.       Width           =   1980
  31.    End
  32.    Begin VB.CommandButton cmdDone 
  33.       Caption         =   "Do&ne"
  34.       Height          =   375
  35.       Left            =   3240
  36.       TabIndex        =   13
  37.       TabStop         =   0   'False
  38.       Top             =   2160
  39.       Width           =   1215
  40.    End
  41.    Begin VB.CommandButton cmdDelete 
  42.       Caption         =   "&Delete"
  43.       Height          =   375
  44.       Left            =   1680
  45.       TabIndex        =   12
  46.       TabStop         =   0   'False
  47.       Top             =   2160
  48.       Width           =   1215
  49.    End
  50.    Begin VB.CommandButton cmdEdit 
  51.       Caption         =   "&Edit"
  52.       Height          =   375
  53.       Left            =   120
  54.       TabIndex        =   11
  55.       TabStop         =   0   'False
  56.       Top             =   2160
  57.       Width           =   1215
  58.    End
  59.    Begin VB.CommandButton cmdCancel 
  60.       Caption         =   "&Cancel"
  61.       Height          =   375
  62.       Left            =   3240
  63.       TabIndex        =   10
  64.       TabStop         =   0   'False
  65.       Top             =   1680
  66.       Width           =   1215
  67.    End
  68.    Begin VB.CommandButton cmdSave 
  69.       Caption         =   "&Save"
  70.       Height          =   375
  71.       Left            =   1680
  72.       TabIndex        =   9
  73.       TabStop         =   0   'False
  74.       Top             =   1680
  75.       Width           =   1215
  76.    End
  77.    Begin VB.CommandButton cmdAddNew 
  78.       Caption         =   "&Add New"
  79.       Height          =   375
  80.       Left            =   120
  81.       TabIndex        =   8
  82.       TabStop         =   0   'False
  83.       Top             =   1680
  84.       Width           =   1215
  85.    End
  86.    Begin VB.CommandButton cmdNext 
  87.       Caption         =   "Next =>"
  88.       Height          =   255
  89.       Left            =   2520
  90.       TabIndex        =   7
  91.       TabStop         =   0   'False
  92.       Top             =   1320
  93.       Width           =   1215
  94.    End
  95.    Begin VB.CommandButton cmdPrevious 
  96.       Caption         =   "<= Previous"
  97.       Height          =   255
  98.       Left            =   1080
  99.       TabIndex        =   6
  100.       TabStop         =   0   'False
  101.       Top             =   1320
  102.       Width           =   1215
  103.    End
  104.    Begin VB.TextBox txtYearBorn 
  105.       DataField       =   "Year Born"
  106.       DataSource      =   "datAuthors"
  107.       Height          =   285
  108.       Left            =   1200
  109.       Locked          =   -1  'True
  110.       TabIndex        =   2
  111.       Text            =   "Text3"
  112.       Top             =   840
  113.       Width           =   1215
  114.    End
  115.    Begin VB.TextBox txtAuthor 
  116.       DataField       =   "Author"
  117.       DataSource      =   "datAuthors"
  118.       Height          =   285
  119.       Left            =   1200
  120.       Locked          =   -1  'True
  121.       TabIndex        =   1
  122.       Text            =   "Text2"
  123.       Top             =   480
  124.       Width           =   3375
  125.    End
  126.    Begin VB.TextBox txtAuthorID 
  127.       DataField       =   "Au_ID"
  128.       DataSource      =   "datAuthors"
  129.       Height          =   285
  130.       Left            =   1200
  131.       Locked          =   -1  'True
  132.       TabIndex        =   3
  133.       TabStop         =   0   'False
  134.       Text            =   "Text1"
  135.       Top             =   120
  136.       Width           =   1215
  137.    End
  138.    Begin VB.Label Label3 
  139.       Caption         =   "Year Born"
  140.       Height          =   255
  141.       Left            =   120
  142.       TabIndex        =   5
  143.       Top             =   840
  144.       Width           =   1215
  145.    End
  146.    Begin VB.Label Label2 
  147.       Caption         =   "Author Name"
  148.       Height          =   255
  149.       Left            =   120
  150.       TabIndex        =   4
  151.       Top             =   480
  152.       Width           =   1215
  153.    End
  154.    Begin VB.Label Label1 
  155.       Caption         =   "Author ID"
  156.       Height          =   255
  157.       Left            =   120
  158.       TabIndex        =   0
  159.       Top             =   120
  160.       Width           =   1215
  161.    End
  162. Attribute VB_Name = "frmAuthors"
  163. Attribute VB_GlobalNameSpace = False
  164. Attribute VB_Creatable = False
  165. Attribute VB_PredeclaredId = True
  166. Attribute VB_Exposed = False
  167. Option Explicit
  168. Private Sub cmdAddNew_Click()
  169. Call SetState("Add")
  170. End Sub
  171. Private Sub cmdCancel_Click()
  172. Call SetState("View")
  173. End Sub
  174. Private Sub cmdDelete_Click()
  175. Dim Response As Integer
  176. Response = MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion + vbDefaultButton2, "Delete")
  177. If Response = vbNo Then
  178.   Exit Sub
  179. End If
  180. End Sub
  181. Private Sub cmdEdit_Click()
  182. Call SetState("Edit")
  183. End Sub
  184. Private Sub cmdNext_Click()
  185. datAuthors.Recordset.MoveNext
  186. If datAuthors.Recordset.EOF Then
  187.   Beep
  188.   datAuthors.Recordset.MoveLast
  189. End If
  190. End Sub
  191. Private Sub cmdPrevious_Click()
  192. datAuthors.Recordset.MovePrevious
  193. If datAuthors.Recordset.BOF Then
  194.   Beep
  195.   datAuthors.Recordset.MoveFirst
  196. End If
  197. End Sub
  198. Private Sub cmdSave_Click()
  199. MsgBox "Record saved.", vbOKOnly + vbInformation, "Save"
  200. Call SetState("View")
  201. End Sub
  202. Private Sub SetState(AppState As String)
  203. Select Case AppState
  204. Case "View"
  205.   txtAuthorID.BackColor = vbWhite
  206.   txtAuthor.Locked = True
  207.   txtYearBorn.Locked = True
  208.   cmdPrevious.Enabled = True
  209.   cmdNext.Enabled = True
  210.   cmdAddNew.Enabled = True
  211.   cmdSave.Enabled = False
  212.   cmdCancel.Enabled = False
  213.   cmdEdit.Enabled = True
  214.   cmdDelete.Enabled = True
  215.   cmdDone.Enabled = True
  216.   txtAuthor.SetFocus
  217. Case "Add", "Edit"
  218.   txtAuthorID.BackColor = vbRed
  219.   txtAuthor.Locked = False
  220.   txtYearBorn.Locked = False
  221.   cmdPrevious.Enabled = False
  222.   cmdNext.Enabled = False
  223.   cmdAddNew.Enabled = False
  224.   cmdSave.Enabled = True
  225.   cmdCancel.Enabled = True
  226.   cmdEdit.Enabled = False
  227.   cmdDelete.Enabled = False
  228.   cmdDone.Enabled = False
  229.   txtAuthor.SetFocus
  230. End Select
  231. End Sub
  232. Private Sub Form_Activate()
  233. Call SetState("View")
  234. End Sub
  235. Private Sub txtYearBorn_KeyPress(KeyAscii As Integer)
  236. If (KeyAscii >= Asc("0") And KeyAscii <= Asc("9")) Or KeyAscii = vbKeyBack Then
  237.   Exit Sub
  238.   Beep
  239.   KeyAscii = 0
  240. End If
  241. End Sub
  242.